package org.stragma.symbian.apply.stratego;

import org.strategoxt.stratego_lib.*;
import org.strategoxt.stratego_lib.*;
import org.strategoxt.lang.*;
import org.spoofax.interpreter.terms.*;
import static org.strategoxt.lang.Term.*;
import org.spoofax.interpreter.library.AbstractPrimitive;
import java.util.ArrayList;
import java.lang.ref.WeakReference;

@SuppressWarnings("all") public class Addassertions  
{ 
  protected static final boolean TRACES_ENABLED = true;

  protected static ITermFactory constantFactory;

  private static WeakReference<Context> initedContext;

  private static boolean isIniting;

  protected static IStrategoTerm constNil0;

  public static IStrategoConstructor _consConc_2;

  public static IStrategoConstructor _consNone_0;

  public static IStrategoConstructor _consSome_1;

  public static IStrategoConstructor _consNot_1;

  public static IStrategoConstructor _consLeq_2;

  public static IStrategoConstructor _consGeq_2;

  public static IStrategoConstructor _consAnd_2;

  public static IStrategoConstructor _consStatements_1;

  public static IStrategoConstructor _consIf_2;

  public static IStrategoConstructor _consIfElse_3;

  public static IStrategoConstructor _consFor_4;

  public static IStrategoConstructor _consAssert_1;

  public static Context init(Context context)
  { 
    synchronized(Addassertions.class)
    { 
      if(isIniting)
        return null;
      try
      { 
        isIniting = true;
        ITermFactory termFactory = context.getFactory();
        if(constantFactory == null)
        { 
          initConstructors(termFactory);
          initConstants(termFactory);
        }
        if(initedContext == null || initedContext.get() != context)
        { 
          org.strategoxt.stratego_lib.Main.init(context);
          org.strategoxt.stratego_lib.Main.init(context);
          context.registerComponent("Addassertions");
        }
        initedContext = new WeakReference<Context>(context);
        constantFactory = termFactory;
      }
      finally
      { 
        isIniting = false;
      }
      return context;
    }
  }

  public static Context init()
  { 
    return init(new Context());
  }

  public static void main(String args[])
  { 
    Context context = init();
    context.setStandAlone(true);
    try
    { 
      IStrategoTerm result;
      try
      { 
        result = context.invokeStrategyCLI(io_$Addassertions_0_0.instance, "Addassertions", args);
      }
      finally
      { 
        context.getIOAgent().closeAllFiles();
      }
      if(result == null)
      { 
        System.err.println("Addassertions" + (TRACES_ENABLED ? ": rewriting failed, trace:" : ": rewriting failed"));
        context.printStackTrace();
        context.setStandAlone(false);
        System.exit(1);
      }
      else
      { 
        //System.out.println(result);
        context.setStandAlone(false);
        System.exit(0);
      }
    }
    catch(StrategoExit exit)
    { 
      context.setStandAlone(false);
      //System.exit(exit.getValue());
    }
  }

  public static IStrategoTerm mainNoExit(String ... args) throws StrategoExit
  { 
    return mainNoExit(new Context(), args);
  }

  public static IStrategoTerm mainNoExit(Context context, String ... args) throws StrategoExit
  { 
    try
    { 
      init(context);
      return context.invokeStrategyCLI(io_$Addassertions_0_0.instance, "Addassertions", args);
    }
    finally
    { 
      context.getIOAgent().closeAllFiles();
    }
  }

  public static Strategy getMainStrategy()
  { 
    return io_$Addassertions_0_0.instance;
  }

  public static void initConstructors(ITermFactory termFactory)
  { 
    _consConc_2 = termFactory.makeConstructor("Conc", 2);
    _consNone_0 = termFactory.makeConstructor("None", 0);
    _consSome_1 = termFactory.makeConstructor("Some", 1);
    _consNot_1 = termFactory.makeConstructor("Not", 1);
    _consLeq_2 = termFactory.makeConstructor("Leq", 2);
    _consGeq_2 = termFactory.makeConstructor("Geq", 2);
    _consAnd_2 = termFactory.makeConstructor("And", 2);
    _consStatements_1 = termFactory.makeConstructor("Statements", 1);
    _consIf_2 = termFactory.makeConstructor("If", 2);
    _consIfElse_3 = termFactory.makeConstructor("IfElse", 3);
    _consFor_4 = termFactory.makeConstructor("For", 4);
    _consAssert_1 = termFactory.makeConstructor("Assert", 1);
  }

  public static void initConstants(ITermFactory termFactory)
  { 
    constNil0 = (IStrategoTerm)termFactory.makeList();
  }

  @SuppressWarnings("all") public static class io_$Addassertions_0_0 extends Strategy 
  { 
    public static io_$Addassertions_0_0 instance = new io_$Addassertions_0_0();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      context.push("io_Addassertions_0_0");
      Fail0:
      { 
        term = io_wrap_1_0.instance.invoke(context, term, add_assertions_0_0.instance);
        if(term == null)
          break Fail0;
        context.popOnSuccess();
        if(true)
          return term;
      }
      context.popOnFailure();
      return null;
    }
  }

  @SuppressWarnings("all") public static class add_assertions_0_0 extends Strategy 
  { 
    public static add_assertions_0_0 instance = new add_assertions_0_0();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      context.push("add_assertions_0_0");
      Fail1:
      { 
        term = topdown_1_0.instance.invoke(context, term, lifted1.instance);
        if(term == null)
          break Fail1;
        context.popOnSuccess();
        if(true)
          return term;
      }
      context.popOnFailure();
      return null;
    }
  }

  @SuppressWarnings("all") public static class $If$Assertion_0_0 extends Strategy 
  { 
    public static $If$Assertion_0_0 instance = new $If$Assertion_0_0();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      ITermFactory termFactory = context.getFactory();
      Fail2:
      { 
        IStrategoTerm term1 = term;
        IStrategoConstructor cons0 = term.getTermType() == IStrategoTerm.APPL ? ((IStrategoAppl)term).getConstructor() : null;
        Success0:
        { 
          if(cons0 == Addassertions._consIf_2)
          { 
            Fail3:
            { 
              IStrategoTerm r_33 = null;
              IStrategoTerm s_33 = null;
              r_33 = term.getSubterm(0);
              IStrategoTerm arg0 = term.getSubterm(1);
              if(arg0.getTermType() != IStrategoTerm.APPL || Addassertions._consStatements_1 != ((IStrategoAppl)arg0).getConstructor())
                break Fail3;
              IStrategoTerm arg1 = arg0.getSubterm(0);
              if(arg1.getTermType() != IStrategoTerm.LIST || ((IStrategoList)arg1).isEmpty())
                break Fail3;
              s_33 = ((IStrategoList)arg1).head();
              IStrategoTerm arg2 = ((IStrategoList)arg1).tail();
              if(arg2.getTermType() != IStrategoTerm.LIST || !((IStrategoList)arg2).isEmpty())
                break Fail3;
              term = termFactory.makeAppl(Addassertions._consIf_2, new IStrategoTerm[]{r_33, termFactory.makeAppl(Addassertions._consStatements_1, new IStrategoTerm[]{(IStrategoTerm)termFactory.makeListCons(termFactory.makeAppl(Addassertions._consAssert_1, new IStrategoTerm[]{r_33}), termFactory.makeListCons(s_33, (IStrategoList)Addassertions.constNil0))})});
              if(true)
                break Success0;
            }
            term = term1;
          }
          if(cons0 == Addassertions._consIfElse_3)
          { 
            IStrategoTerm o_33 = null;
            IStrategoTerm p_33 = null;
            IStrategoTerm q_33 = null;
            p_33 = term.getSubterm(0);
            IStrategoTerm arg3 = term.getSubterm(1);
            if(arg3.getTermType() != IStrategoTerm.APPL || Addassertions._consStatements_1 != ((IStrategoAppl)arg3).getConstructor())
              break Fail2;
            IStrategoTerm arg4 = arg3.getSubterm(0);
            if(arg4.getTermType() != IStrategoTerm.LIST || ((IStrategoList)arg4).isEmpty())
              break Fail2;
            o_33 = ((IStrategoList)arg4).head();
            IStrategoTerm arg5 = ((IStrategoList)arg4).tail();
            if(arg5.getTermType() != IStrategoTerm.LIST || !((IStrategoList)arg5).isEmpty())
              break Fail2;
            IStrategoTerm arg6 = term.getSubterm(2);
            if(arg6.getTermType() != IStrategoTerm.APPL || Addassertions._consStatements_1 != ((IStrategoAppl)arg6).getConstructor())
              break Fail2;
            IStrategoTerm arg7 = arg6.getSubterm(0);
            if(arg7.getTermType() != IStrategoTerm.LIST || ((IStrategoList)arg7).isEmpty())
              break Fail2;
            q_33 = ((IStrategoList)arg7).head();
            IStrategoTerm arg8 = ((IStrategoList)arg7).tail();
            if(arg8.getTermType() != IStrategoTerm.LIST || !((IStrategoList)arg8).isEmpty())
              break Fail2;
            term = termFactory.makeAppl(Addassertions._consIfElse_3, new IStrategoTerm[]{p_33, termFactory.makeAppl(Addassertions._consStatements_1, new IStrategoTerm[]{(IStrategoTerm)termFactory.makeListCons(termFactory.makeAppl(Addassertions._consAssert_1, new IStrategoTerm[]{p_33}), termFactory.makeListCons(o_33, (IStrategoList)Addassertions.constNil0))}), termFactory.makeAppl(Addassertions._consStatements_1, new IStrategoTerm[]{(IStrategoTerm)termFactory.makeListCons(termFactory.makeAppl(Addassertions._consAssert_1, new IStrategoTerm[]{termFactory.makeAppl(Addassertions._consNot_1, new IStrategoTerm[]{p_33})}), termFactory.makeListCons(q_33, (IStrategoList)Addassertions.constNil0))})});
          }
          else
          { 
            break Fail2;
          }
        }
        if(true)
          return term;
      }
      context.push("IfAssertion_0_0");
      context.popOnFailure();
      return null;
    }
  }

  @SuppressWarnings("all") public static class $For$Assertion_0_0 extends Strategy 
  { 
    public static $For$Assertion_0_0 instance = new $For$Assertion_0_0();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      ITermFactory termFactory = context.getFactory();
      Fail4:
      { 
        IStrategoTerm t_33 = null;
        IStrategoTerm u_33 = null;
        IStrategoTerm v_33 = null;
        IStrategoTerm w_33 = null;
        if(term.getTermType() != IStrategoTerm.APPL || Addassertions._consFor_4 != ((IStrategoAppl)term).getConstructor())
          break Fail4;
        u_33 = term.getSubterm(0);
        t_33 = term.getSubterm(1);
        v_33 = term.getSubterm(2);
        w_33 = term.getSubterm(3);
        term = termFactory.makeAppl(Addassertions._consFor_4, new IStrategoTerm[]{u_33, t_33, v_33, termFactory.makeAppl(Addassertions._consStatements_1, new IStrategoTerm[]{(IStrategoTerm)termFactory.makeListCons(termFactory.makeAppl(Addassertions._consAssert_1, new IStrategoTerm[]{termFactory.makeAppl(Addassertions._consAnd_2, new IStrategoTerm[]{termFactory.makeAppl(Addassertions._consGeq_2, new IStrategoTerm[]{u_33, t_33}), termFactory.makeAppl(Addassertions._consLeq_2, new IStrategoTerm[]{u_33, v_33})})}), termFactory.makeListCons(w_33, (IStrategoList)Addassertions.constNil0))})});
        if(true)
          return term;
      }
      context.push("ForAssertion_0_0");
      context.popOnFailure();
      return null;
    }
  }

  @SuppressWarnings("all") public static class main_0_0 extends Strategy 
  { 
    public static main_0_0 instance = new main_0_0();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      context.push("main_0_0");
      Fail5:
      { 
        term = io_$Addassertions_0_0.instance.invoke(context, term);
        if(term == null)
          break Fail5;
        context.popOnSuccess();
        if(true)
          return term;
      }
      context.popOnFailure();
      return null;
    }
  }

  @SuppressWarnings("all") private static final class lifted1 extends Strategy 
  { 
    public static final lifted1 instance = new lifted1();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      Fail6:
      { 
        term = try_1_0.instance.invoke(context, term, lifted2.instance);
        if(term == null)
          break Fail6;
        if(true)
          return term;
      }
      return null;
    }
  }

  @SuppressWarnings("all") private static final class lifted2 extends Strategy 
  { 
    public static final lifted2 instance = new lifted2();

    @Override public IStrategoTerm invoke(Context context, IStrategoTerm term)
    { 
      Fail7:
      { 
        IStrategoTerm term0 = term;
        Success1:
        { 
          Fail8:
          { 
            term = $If$Assertion_0_0.instance.invoke(context, term);
            if(term == null)
              break Fail8;
            if(true)
              break Success1;
          }
          term = $For$Assertion_0_0.instance.invoke(context, term0);
          if(term == null)
            break Fail7;
        }
        if(true)
          return term;
      }
      return null;
    }
  }

  public static void registerInterop(org.spoofax.interpreter.core.IContext context, Context compiledContext)
  { 
    new InteropRegisterer().registerLazy(context, compiledContext, InteropRegisterer.class.getClassLoader());
  }

  @SuppressWarnings("unused") public static class InteropRegisterer extends org.strategoxt.lang.InteropRegisterer 
  { 
    @Override public void register(org.spoofax.interpreter.core.IContext context, Context compiledContext)
    { 
      register(context, compiledContext, context.getVarScope());
    }

    @Override public void registerLazy(org.spoofax.interpreter.core.IContext context, Context compiledContext, ClassLoader classLoader)
    { 
      registerLazy(context, compiledContext, classLoader, context.getVarScope());
    }

    private void register(org.spoofax.interpreter.core.IContext context, Context compiledContext, org.spoofax.interpreter.core.VarScope varScope)
    { 
      compiledContext.registerComponent("Addassertions");
      Addassertions.init(compiledContext);
      varScope.addSVar("io_Addassertions_0_0", new InteropSDefT(io_$Addassertions_0_0.instance, context));
      varScope.addSVar("add_assertions_0_0", new InteropSDefT(add_assertions_0_0.instance, context));
      varScope.addSVar("IfAssertion_0_0", new InteropSDefT($If$Assertion_0_0.instance, context));
      varScope.addSVar("ForAssertion_0_0", new InteropSDefT($For$Assertion_0_0.instance, context));
      varScope.addSVar("main_0_0", new InteropSDefT(main_0_0.instance, context));
    }

    private void registerLazy(org.spoofax.interpreter.core.IContext context, Context compiledContext, ClassLoader classLoader, org.spoofax.interpreter.core.VarScope varScope)
    { 
      compiledContext.registerComponent("Addassertions");
      Addassertions.init(compiledContext);
      varScope.addSVar("io_Addassertions_0_0", new InteropSDefT(classLoader, "Addassertions$io_$Addassertions_0_0", context));
      varScope.addSVar("add_assertions_0_0", new InteropSDefT(classLoader, "Addassertions$add_assertions_0_0", context));
      varScope.addSVar("IfAssertion_0_0", new InteropSDefT(classLoader, "Addassertions$$If$Assertion_0_0", context));
      varScope.addSVar("ForAssertion_0_0", new InteropSDefT(classLoader, "Addassertions$$For$Assertion_0_0", context));
      varScope.addSVar("main_0_0", new InteropSDefT(classLoader, "Addassertions$main_0_0", context));
    }
  }
}